

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>agpy.reg_gal2cel &mdash; agpy 0.1.2 documentation</title>
    
    <link rel="stylesheet" href="../../_static/extra.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="agpy 0.1.2 documentation" href="../../index.html" />
    <link rel="up" title="agpy" href="../agpy.html" />
     
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setDomainName', 'pyspeckit.bitbucket.org']);
      _gaq.push(['_setAllowHash', false]);
      _gaq.push(['_trackPageview']);


    </script>
    <link rel="stylesheet" type="text/css" href="../../_static/extra.css" />
  </head>
  <body>
    <div class="header-wrapper">
      <div class="header">
        <h1><a href="../../index.html">agpy 0.1.2 documentation</a></h1>
        <div class="rel">
          <a href="http://agpy.googlecode.com">agpy Home </a>  |
          <a href=../../index.html>Docs Home </a>  |
          <a href="http://code.google.com/p/agpy/w/list">Wiki</a>  |
          <a href=../../search.html>Search </a>
        </div>
       </div>
    </div>

    <div class="content-wrapper">
      <div class="content">
        <div class="document">
            
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for agpy.reg_gal2cel</h1><div class="highlight"><pre>
<span class="k">try</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">coords</span>
    <span class="kn">import</span> <span class="nn">pyregion</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="k">print</span> <span class="s">&quot;reg_gal2cel requires coords &amp; pyregion&quot;</span>
<span class="kn">import</span> <span class="nn">posang</span>

<div class="viewcode-block" id="gal2cel"><a class="viewcode-back" href="../../agpy.html#agpy.reg_gal2cel.gal2cel">[docs]</a><span class="k">def</span> <span class="nf">gal2cel</span><span class="p">(</span><span class="n">regfile</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Converts a region file from galactic to celestial coordinates including</span>
<span class="sd">    position angle reference from the center of the box (right now only works</span>
<span class="sd">    on box regions)</span>

<span class="sd">    Requires pyregion with the ShapeList.write() function implemented...</span>
<span class="sd">    not clear if that exists in 1.0</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">reg</span> <span class="o">=</span> <span class="n">pyregion</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">regfile</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">R</span> <span class="ow">in</span> <span class="n">reg</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">R</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="s">&#39;box&#39;</span><span class="p">:</span>
            <span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">dx</span><span class="p">,</span><span class="n">dy</span><span class="p">,</span><span class="n">angle</span> <span class="o">=</span> <span class="n">R</span><span class="o">.</span><span class="n">coord_list</span>

            <span class="n">posn</span> <span class="o">=</span> <span class="n">coords</span><span class="o">.</span><span class="n">Position</span><span class="p">([</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">],</span><span class="n">system</span><span class="o">=</span><span class="s">&#39;galactic&#39;</span><span class="p">)</span>
            <span class="n">ra</span><span class="p">,</span><span class="n">dec</span> <span class="o">=</span> <span class="n">posn</span><span class="o">.</span><span class="n">j2000</span><span class="p">()</span>

            <span class="n">newang</span> <span class="o">=</span> <span class="n">posang</span><span class="o">.</span><span class="n">posang</span><span class="p">(</span><span class="n">x</span><span class="o">-</span><span class="n">dx</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">x</span><span class="o">+</span><span class="n">dx</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">system</span><span class="o">=</span><span class="s">&#39;galactic&#39;</span><span class="p">)</span>

            <span class="n">coord_list</span> <span class="o">=</span> <span class="p">[</span><span class="n">ra</span><span class="p">,</span><span class="n">dec</span><span class="p">,</span><span class="n">dx</span><span class="p">,</span><span class="n">dy</span><span class="p">,</span><span class="n">angle</span><span class="o">-</span><span class="n">newang</span><span class="o">-</span><span class="mi">90</span><span class="p">]</span>

            <span class="n">R</span><span class="o">.</span><span class="n">coord_format</span> <span class="o">=</span> <span class="s">&#39;fk5&#39;</span>
            <span class="n">R</span><span class="o">.</span><span class="n">coord_list</span> <span class="o">=</span> <span class="n">coord_list</span>
            <span class="n">R</span><span class="o">.</span><span class="n">params</span> <span class="o">=</span> <span class="n">coord_list</span>

    <span class="n">reg</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">regfile</span><span class="p">[:</span><span class="o">-</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s">&quot;_fk5.reg&quot;</span><span class="p">)</span>
</pre></div></div>

          </div>
        </div>
      </div>
        </div>
        <div class="sidebar">
          <h3>Table Of Contents</h3>
          <ul>
<li class="toctree-l1"><a class="reference internal" href="../../agpy.html">Adam Ginsburg&#8217;s Python Code (agpy)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../image_tools.html">Image Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../fft_tools.html">AG_fft_tools Package</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../plfit.html">plfit Package</a></li>
</ul>

          <h3 style="margin-top: 1.5em;">Search</h3>
          <form class="search" action="../../search.html" method="get">
            <input type="text" name="q" />
            <input type="submit" value="Go" />
            <input type="hidden" name="check_keywords" value="yes" />
            <input type="hidden" name="area" value="default" />
          </form>
          <p class="searchtip" style="font-size: 90%">
            Enter search terms or a module, class or function name.
          </p>
        </div>
        <div class="clearer"></div>
      </div>
    </div>

    <div class="footer">
      &copy; Copyright 2011, Adam Ginsburg.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2pre.
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-6253248-2']);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();

    </script>
        
    </div>
  </body>
</html>